package com.ryskoo.catering.productmain.repository;

import com.ryskoo.catering.constant.HCLCacheConstant;
import com.ryskoo.catering.productmain.domain.ProductMainPO;
import com.ryskoo.framework.core.bean.QueryMessageDTO;
import com.ryskoo.framework.core.repository.BasicRedisImpl;
import com.ryskoo.framework.core.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import java.util.List;

@Primary
@Repository
public class ProductMainRedisImpl extends BasicRedisImpl<ProductMainPO> implements IProductMainRepository {
    @Autowired
    private RedisUtil redisClient;

    @Autowired
    private IProductMainRepository productRepository;

    @PostConstruct
    public void init() {
        this.setRedisClient(redisClient);
        this.setDao(productRepository);
    }

    public ProductMainRedisImpl() {
        super(HCLCacheConstant.HCL_PRODUCT_KEY);
    }

    @Override
    public void onShelves(List<String> idList) {
        productRepository.onShelves(idList);
    }

    @Override
    public void offShelves(List<String> idList) {
        productRepository.offShelves(idList);
    }

    @Override
    public List<String> getUuidsByCategoryId(String categoryUuid) {
        return productRepository.getUuidsByCategoryId(categoryUuid);
    }

    @Override
    public void syncToElastic(List<ProductMainPO> list) {
        productRepository.syncToElastic(list);
    }

    @Override
    public List<ProductMainPO> getProductInfoFromES(QueryMessageDTO qm, boolean byPage) {
        return productRepository.getProductInfoFromES(qm, byPage);
    }

    @Override
    public int getCountFromES(QueryMessageDTO qm) {
        return productRepository.getCountFromES(qm);
    }

    @Override
    public void deleteProductFromES(List<String> idList) {
        productRepository.deleteProductFromES(idList);
    }

    @Override
    public void sellOut(List<String> idList) {
        productRepository.sellOut(idList);
    }

    @Override
    public void supply(List<String> idList) {
        productRepository.supply(idList);
    }
}
